/*
	Author:		Lucas Azevedo
	Version: 	1.0.0
	(c) 2013 GNU General Public License
	
*/

(function(la){
	la.fn.latooltip = function(options){
		var defaults = {
			imgTop:'util/img/tooltipTop.png',
			imgBottom:'util/img/tooltipBottom.png',
			background:'#ddd',
			borderColor:'#555',
			borderSize:'2px',
			width:360,
			textAlign:'center',
			cursor:'help',
			color:'black'
		};
		var settings = la.extend({},defaults, options);
		if(isNaN(settings.width)){
			settings.width = settings.width.replace('px','');
		}
		this.each(function(){
		
			la(this).mouseenter(function(){
				var tooltipitem = la(this);
				la('<div id="latooltipcontainer">').css({
					display:'block',
					width:settings.width,
					position:'absolute',
					zIndex:999999
				}).appendTo('body');
				tooltipitem.css({cursor:settings.cursor});
				$('<img>').attr({
					src:settings.imgTop,
					margin:0
				}).appendTo('#latooltipcontainer');
				tooltipitem.next().clone().css({
					borderRight:settings.borderSize+" solid "+settings.borderColor,
					borderLeft:settings.borderSize+" solid "+settings.borderColor,
					width:settings.width-4,
					margin:0,
					color:settings.color,
					marginTop:-5,
					textAlign:settings.textAlign,
					background:settings.background,
					display:'block'
				}).appendTo('#latooltipcontainer');
				$('<img>').attr({
					src:settings.imgBottom
				}).appendTo('#latooltipcontainer');
				la('#latooltipcontainer').css({
					top:tooltipitem.offset().top+tooltipitem.height()+5,
					left:tooltipitem.offset().left-(la('#latooltipcontainer').width()/2)+(tooltipitem.width()/2)
				});
			}).mouseleave(function(){
				la('#latooltipcontainer').remove();
			});
		});
	};
})(jQuery);